SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


CREATE PROCEDURE dbo.[DnnProduct_AddSearchItemWord]
   @SearchItemID  INT,
   @SearchWordsID INT,
   @Occurrences   INT
AS
  DECLARE  @ID INT
  SELECT @id = SearchItemWordId
  FROM   dbo.DnnProduct_SearchItemWord
  WHERE  SearchItemId = @SearchItemID
         AND SearchWordsId = @SearchWordsID
  IF @ID IS NULL
    BEGIN
      INSERT INTO dbo.DnnProduct_SearchItemWord
                 ([SearchItemId],
                  [SearchWordsId],
                  [Occurrences])
      VALUES     (@SearchItemID,
                  @SearchWordsID,
                  @Occurrences)
      SELECT Scope_identity()
    END
  ELSE
    BEGIN
      UPDATE dbo.DnnProduct_SearchItemWord
      SET    Occurrences = @Occurrences
      WHERE  SearchItemWordId = @id
             AND Occurrences <> @Occurrences
      SELECT @id
    END
GO
